package com.igroupes.ovineherd.rpc.client;

import com.igroupes.ovineherd.aop.FeignRequestInterceptor;
import com.igroupes.ovineherd.dto.UserInfo;
import com.igroupes.ovineherd.vo.ResultVO;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name="ovapi",path = "ovapi/rpc/user",fallbackFactory = UserService.FeignClientFB.class, configuration = FeignRequestInterceptor.class
)
public interface UserService {

    @GetMapping(value = "info",headers = "content-type=application/json")
    ResultVO<UserInfo> infoByToken(@RequestParam("token") String token);

    /**
     * 服务降级内部类
     */
    @Component
    @Slf4j
    class FeignClientFB implements FallbackFactory<UserService> {

        @Override
        public UserService create(Throwable cause) {
            return new UserService() {

                @Override
                public ResultVO infoByToken(String token) {
                    return ResultVO.success(null);
                }
            };
        }
    }
}
